Platform independence
In this part of the assignment, change your compiler to emit platform-independent code for IO.
To do so, follow the guidance from the class notes to:
- Create a “runtime” C file that implements functions to print strings and numbers.
- Assemble this code and link it with the C standard library and code emitted by your compiler.
- Update the parser and emitter to make use of the new IO functions and to support the following grammar:
\[ \definecolor{myblue}{RGB}{37, 104, 145} \newcommand{gt}[1]{{\color{myblue}\underline{#1}}\quad} \newcommand{gnt}[1]{\mathit{#1}\quad} \newcommand{\Program}{\gnt{Program}} \newcommand{\STR}{\gt{STR}} \newcommand{\Expr}{\gnt{Expr}} \newcommand{\INT}{\gt{INT}} \newcommand{\prod}{\rightarrow\quad} \newcommand{\alt}{\ |\ \quad} \]
\[ \begin{align} \Program \prod & \gt{printString} \STR \\ \alt & \gt{printNumber} \Expr \\ \\ \Expr \prod & \Expr \gt{+} \Expr \\ \alt & \Expr \gt{-} \Expr \\ \alt & \Expr \gt{*} \Expr \\ \alt & \gt{(} \Expr \gt{)} \\ \alt & \INT \end{align} \]
This grammar is slightly different than the one presented in class. It has a different name for the instruction that prints a number. If you implemented the grammar from class, or another one close to it, that’s okay!
With these changes, the compiler no longer needs to return the result of the evaluated expression as part of sys_exit. If the end-user (i.e., the hmc programmer) wants to know the value of the expression, they now can print it!